//
//  UPSheZhiItem.m
//  Uang Pasti
//
//  Created by 李永彬 on 2025/8/18.
//

#import "UPSheZhiItem.h"

@interface UPSheZhiItem()

@property (nonatomic, assign) UPSetItemType itemType;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *versionLabel;
@property (nonatomic, strong) UIImageView *arrowImgView;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, assign) CGFloat alpha;
@end

@implementation UPSheZhiItem

- (instancetype)initWithItemType:(UPSetItemType)itemType title:(NSString *)title alpha: (CGFloat)alpha {
    self = [super init];
    self.itemType = itemType;
    self.title =  title;
    self.alpha = alpha;
    if (self) {
        [self setupView];
    }
    return self;
}

- (void)setupView {
    self.alpha = self.alpha;
    self.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF"];
    self.layer.masksToBounds = YES;
    self.layer.cornerRadius = 13.0;
    self.layer.borderWidth = 2.0;
    self.layer.borderColor = [UIColor colorWithHexString:@"#000000"].CGColor;
    self.userInteractionEnabled = YES;
    
    [self addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self).offset(16);
        make.centerY.equalTo(self);
    }];
    
    [self addSubview:self.versionLabel];
    [self.versionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(self).offset(-16);
        make.centerY.equalTo(self);
    }];
    
    [self addSubview:self.arrowImgView];
    [self.arrowImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(self).offset(-16);
        make.centerY.equalTo(self);
        make.width.equalTo(@20);
        make.height.equalTo(@33);
    }];
}

- (void)setItemType:(UPSetItemType)itemType {
    switch (itemType) {
        case UPSetItemTypeA:
            [self.versionLabel setHidden:YES];
            [self.arrowImgView setHidden:NO];
            break;
        case UPSetItemTypeB:
            [self.versionLabel setHidden:NO];
            [self.arrowImgView setHidden:YES];
            break;
    }
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = [UIColor colorWithHexString:@"#000000"];
        _titleLabel.font = [UIFont systemFontOfSize:13 weight:UIFontWeightSemibold];
        _titleLabel.textAlignment = NSTextAlignmentLeft;
        _titleLabel.text = self.title;
    }
    return _titleLabel;
}

- (UILabel *)versionLabel {
    if (!_versionLabel) {
        _versionLabel = [[UILabel alloc] init];
        _versionLabel.textColor = [UIColor colorWithHexString:@"#000000"];
        _versionLabel.font = [UIFont systemFontOfSize:13 weight:UIFontWeightSemibold];
        _versionLabel.textAlignment = NSTextAlignmentRight;
        _versionLabel.text = @"1.0.0";
    }
    return _versionLabel;
}

- (UIImageView *)arrowImgView {
    if (!_arrowImgView) {
        _arrowImgView = [[UIImageView alloc] init];
        _arrowImgView.image = [UIImage imageNamed:@"go_forward_arrow"];
        _arrowImgView.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _arrowImgView;
}

@end
